<template>
	<view class="follow">
		<!-- 导航切换 -->
		<view class="follow-tab">
			<view class="follow-tab__box">
				<view class="follow-tab__item" :class="{active:isActive === 0}" @click="tab(0)">文章</view>
				<view class="follow-tab__item" :class="{active:isActive === 1}" @click="tab(1)">作者</view>
			</view>
		</view>
		<view class="follow-list">
			<swiper class="follow-list__swiper" :current="isActive" @change="change">
				<swiper-item>
					<list-scroll>
						<uni-load-more v-if="list.length === 0 && !articleShow" iconType="snow" status="loading"></uni-load-more>
						<view class="no-data" v-if="articleShow">没有数据</view>
						<list-card types="follow" v-for="item in list" :key="item._id" :item="item"></list-card>
					</list-scroll>
				</swiper-item>
				<swiper-item>
					<list-scroll>
						<list-author v-for="item in authorList" :item="item" :key=item.id></list-author>
					</list-scroll>
				</swiper-item>
			</swiper>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isActive: 0,
				list: [],
				articleShow: false,
				authorList: []
			}
		},
		onLoad(){
			uni.$on('update_article', () => {
				console.log('关注页面触发')
				this.getFollow()
			})
			uni.$on('update_author', () => {
				this.getAuthor()
			})
			this.getAuthor()
			this.getFollow()
		},
		methods: {
			tab(num){
				this.isActive = num
			},
			getFollow(){
				this.$api.get_follow().then(res => {
					const {
						data
					} = res
					this.list = data
					this.articleShow = this.list.length === 0 ? true : false
				})
			},
			change(e){
				const current = e.detail.current
				this.isActive = current
			},
			getAuthor(){
				this.$api.get_author().then(res => {
					const {data} = res
					this.authorList = data
				})
			}
		}
	}
</script>

<style lang="scss">
	page{
		height: 100%;
		display: flex;
	}
	.follow{
		height: 100%;
		display: flex;
		flex-direction: column;
		flex: 1;
		box-sizing: border-box;
		.follow-tab{
			height: 30px;
			padding: 10px 20px;
			border-bottom: 1px #F5F5F5 solid;
			.follow-tab__box{
				display: flex;
				width: 100%;
				height: 100%;
				border-radius: 5px;
				border: 1px solid $mk-base-color;
				.follow-tab__item{
					display: flex;
					justify-content: center;
					align-items: center;
					width: 100%;
					font-size: 14px;
					color: #666;
					&:first-child{
						border-right: 1px solid $mk-base-color;
					}
					&.active{
						color: $mk-base-color;
					}
				}
			}
		}
		.follow-list{
			flex: 1;
			.follow-list__swiper{
				height: 100%;
				.swiper-item{
					height: 100%;
				}
			}
		}
	}
	.no-data{
		padding: 50px;
		font-size: 14px;
		color: #999;
		text-align: center;
	}
</style>
